package com.link.base.wechat.common.controller;

import com.link.base.wechat.common.service.WxCommonService;
import com.link.core.basic.model.BasicModel;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信开发者模式下，消息事件接入
 *
 * @author ouyangzhenqiang
 * @date 2019/03/10 23:39
 */
@Controller
@RequestMapping("/link/wxCommon")
public class WxCommonController {
    @Resource
    private WxCommonService wxCommonService;

    /**
     * 获取微信二维码
     *
     * @author Ninglanhao
     * @date 2019/03/11 15:41
     */
    @RequestMapping(value = {"/createForeverQrCode"}, method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> createForeverQrCode(@RequestBody BasicModel record, HttpSession session,
                                                   HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<>(4);
        try {
            String foreverQrCode = wxCommonService.createForeverQrCode(record.getAttr1(), record.getAttr2());
            result.put("success", true);
            result.put("result", foreverQrCode);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
